package cn.com.hhrcw.excel.convert;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.metadata.data.WriteCellData;

import java.math.BigDecimal;

/**
 * BigDecimal转百分比
 *
 * @author lixingxing
 */

public class BigDecimalToRateConvert implements Converter<BigDecimal> {

    @Override
    public Class<?> supportJavaTypeKey() {
        return BigDecimal.class;
    }

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<BigDecimal> context) throws Exception {
        BigDecimal value = context.getValue();
        String rate = value.multiply(new BigDecimal("100")) + "%";
        return new WriteCellData<>(rate);
    }
}
